//
//  QuestionViewController.m
//  Demo
//
//  Created by Echo on 13-10-18.
//

#import "QuestionViewController.h"
#import "UIBarButtonItemCategory.h"

@interface QuestionViewController ()

@end

@implementation QuestionViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.title = STR(@"常见问题");
    if ([Global curLanguageEn]) {
        self.title = @"FAQ";
    }
    [super viewDidLoad];
//    self.view.backgroundColor = RGB(240, 249, 255, 1);
    
    
    UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 15, 320, kScreenHeight-30)];
    [self.view addSubview:scrollview];
    
    NSString *questionPath = [[NSBundle mainBundle] pathForResource:@"question" ofType:@"xml"];
    if ([Global curLanguageEn]) {
        questionPath = [[NSBundle mainBundle] pathForResource:@"questionEN" ofType:@"xml"];
    }
    NSData *cityData = [NSData dataWithContentsOfFile:questionPath];
    NSString *fileText = [[NSString alloc] initWithData:cityData encoding:NSUTF8StringEncoding]; //NSUTF8StringEncoding
    
    UIBarButtonItem *leftItem = [UIBarButtonItem backImageBarButtonItem:[UIImage imageNamed:@"back.png"] target:self action:@selector(cancel)];
    self.navigationItem.leftBarButtonItem = leftItem;

    //初始化label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = RGB(255, 255, 255, 1);
    //设置自动行数与字符换行
    [label setNumberOfLines:0];
    label.lineBreakMode = NSLineBreakByWordWrapping;
    // 测试字串
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    //设置一个行高上限
    CGSize size = CGSizeMake(scrollview.frame.size.width-30, 20000);
    //计算实际frame大小，并将label的frame变成实际大小
    
    CGSize labelsize = [fileText sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    label.frame = CGRectMake(15, 0, scrollview.frame.size.width-30, labelsize.height);
    label.font = font;
    label.text = fileText;
    [scrollview addSubview:label];
    
    
    scrollview.contentSize = CGSizeMake(scrollview.frame.size.width, labelsize.height+50);
    
}
-(void)cancel{
    [self.navigationController popViewControllerAnimated:YES];
}

@end














